import {searchTemperature}  from '../../services/cabinet/cabinet';

export default {
  namespace: 'temperature',
  state: {
    loading:false,
    list: [],
    roomList:[],
    current : 1,
    currentSize : 10,
    total : 0,
   
  },
  reducers: {
    upState(state, { payload }) {
      return { ...state, ...payload };
    },
   
   },
  effects: {    
    *queryList({ payload },{ call, put }) {
      const { body } = yield call(searchTemperature,payload);
      yield put({ type: 'upState', payload: { list:body.data, current:body.current, currentSize:body.size, total:body.iTotalRecords}});
    }, 
  
  },

  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => {
        if (pathname === '/temperature') {
          dispatch({ type: 'queryList',payload: { "assetName":""} });
        
        }
      });
    },
  },
};
